package com.atguigu.gmall.fastdfs;

import com.atguigu.gmall.model.user.UserInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @Auther 赵乾坤
 * @Date 2020-12-25 12:39
 */
public class JSONDemo {

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        //包含不是null

        UserInfo userInfo = new UserInfo();
        userInfo.setId(123L);

        //@Re
        String string = objectMapper.writeValueAsString(userInfo);//写成字符串
        System.out.println(string);

//        UserInfo userInfo1 = objectMapper.readValue(string, UserInfo.class);
//        System.out.println(userInfo1);
//
//        ObjectMapper objectMapper1 = new ObjectMapper();
//        objectMapper1.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//
//        UserInfo userInfo2 = new UserInfo();
//        userInfo2.setId(124L);
//
//        objectMapper1.writeValueAsString(userInfo);
//        System.out.println(userInfo2);
    }

}
